package com.zwf.mapper;

import com.github.pagehelper.Page;
import com.zwf.annotation.AutoFill;
import com.zwf.dto.DishPageQueryDTO;
import com.zwf.entity.Dish;
import com.zwf.enumeration.OperationType;
import com.zwf.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @Author zwf
 * @date 2024/2/1 15:10
 * @PackageName:com.zwf.mapper
 * @ClassName:DishMapper
 * @Description: TODO
 * @Version: 1.0
 */
@Mapper
public interface DishMapper {
    /**
     * 根据分类id查询关联的菜品数
     * @param id
     * @return
     */
    @Select("select count(id) from dish where category_id=#{id}")
    int count(Long id);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void add(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id =#{id}")
    Dish queryById(Long id);

    /**
     * 根据分类id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where category_id=#{id}")
    List<Dish> queryByCategoryId(Long id);

    /**
     * 修改菜品信息
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 批量删除菜品
     * @param id
     */
    @Delete("delete from dish where id=#{id}")
    void delete(Long id);

    /**
     * 条件查询菜品列表
     * @param dish
     */
    List<Dish> query(Dish dish);

    /**
     * 根据状态查询菜品
     * @param status
     * @return
     */
    @Select("select count(*) from dish where status=#{status}")
    Integer countByStatus(Integer status);
}
